<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //字面量模式
        let jxd = {
            name: "姜旭东",
            age: 22,
            fav: ["唱歌", "游戏", "打篮球", "睡觉"],
            friend: {
                name: "苍老师",
                gender: "女"
            },
            say: function () {
                console.log(`大家好，我叫${this.name}`);
            }
        };
        //工厂模式
        function createPerson(name, age, fav, friendName, friendGender) {
            let obj = {
                name: name,
                age: age,
                fav: fav,
                friend: {
                    name: friendName,
                    gender: friendGender
                },
                say: function () {
                    console.log(`大家好，我叫${this.name}`);
                }
            };
            return obj
        }

        let cxf = createPerson('程显富', 23, ['打游戏', '看电影'], '大桥未久', '女')
        let wy = createPerson('吴语', 17, ['打游戏', '看电影'], '泷泽萝拉', '女')

        // 构造函数模式
        function Person(name, age, fav, friendName, friendGender) {
            this.name = name
            this.age = age
            this.fav = fav
            this.friend = {}
            this.friend.name = friendName
            this.friend.gender = friendGender

            this.hello = function () {
                console.log(`大家好，我叫${this.name}`);
            }

            this.say = function () {
                console.log(`我喜欢${this.friend.name}`)
            }
        }

        let myx = new Person('毛一鑫', 20, ['打游戏', '看电影'], '波多', '女')
        let kql = new Person('毛一鑫', 20, ['打游戏', '看电影'], '波多', '女')
    </script>
</body>

</html>